package com.ruoyi.system.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.ComTenant;
import com.ruoyi.system.mapper.ComTenantMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 租户Service业务层处理
 * 
 * @author tianl
 * @date 2025-03-20
 */
@Service
public class ComTenantService extends ServiceImpl<ComTenantMapper, ComTenant> {

    /**
     * 分页查询租户
     *
     */
    public IPage<ComTenant> listPage(ComTenant req) {
        return baseMapper.list(PageUtils.page(), req);
    }

    /**
     * 查询租户列表
     *
     */
    public List<ComTenant> list(ComTenant req) {
        return baseMapper.list(req);
    }

    /**
     * 根据ID查询
     * 
     */
    public ComTenant selectById(Long id) {
        return baseMapper.selectById(id);
    }

    /**
     * 新增修改租户
     * 
     */
    @Transactional(rollbackFor = Exception.class)
    public void beforeSave(ComTenant comTenant) {
        if(comTenant.getId()!=null){
            comTenant.setUpdateTime(DateUtils.getNowDate());
        }else{
            comTenant.setCreateTime(DateUtils.getNowDate());
            comTenant.setUpdateTime(DateUtils.getNowDate());
        }
        saveOrUpdate(comTenant);
    }

    /**
     * 批量删除租户
     *
     */
    @Transactional(rollbackFor = Exception.class)
    public int deleteByIds(List<Long> ids) {
        return baseMapper.deleteBatchIds(ids);
    }

}
